package edu.zut.hb.software.capiturevictor.message.producer;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.Connection;
import org.apache.activemq.spring.ActiveMQConnectionFactoryFactoryBean;

public class producer {

	public static void main(String[] args) throws JMSException, IOException {
	    
	    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
	    javax.jms.Connection connection = connectionFactory.createConnection();
	    connection.start();
	    Session session = connection.createSession(Boolean.FALSE,Session.AUTO_ACKNOWLEDGE);
	    Destination destination = session.createQueue("queue");
	    MessageProducer producer = session.createProducer(destination);
	    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
	    
	    TextMessage textMessage = session.createTextMessage();
	    textMessage.setText(getString());
	    producer.send(textMessage);
	    
	    if(connection!=null){
	        connection.close();
	    }
	}

	private static String getString() throws IOException {
		// TODO Auto-generated method stub
		String dir = "D:\\cptvt\\capiturevictor\\source.txt";
		File file = new File(dir);
		

		//创建FileReader对象，读取文件中的内容
		FileReader reader = new FileReader(file);
		char[] ch = new char[100];
		reader.read(ch);
		reader.close();
		String content = String.valueOf(ch);
		return content;
	}
}